@extends('admin.admin')

@section('content')
<link rel="stylesheet" href="{{ asset('/js/bootstrap-switch/css/bootstrap-switch.min.css') }}">
<!-- Content Header (Page header) -->
<section class="content-header">
    <h1>
        产品管理
        <small>产品列表</small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="/admin"><i class="fa fa-dashboard"></i> 控制面板</a></li>
        <li ><a href="/admin/product">产品管理</a></li>
        <li class="active">产品列表</li>
    </ol>
</section>

<!-- Main content -->
<section class="content">

    <div class="row">
        <div class="col-xs-12">

            <div class="box box-primary">
                <div class="box-header">
                    <h3 class="box-title">产品列表</h3>
                    <div class="box-tools">
                        <a href="{{route('admin.product.create')}}" type="button" class="btn btn-block btn-success btn-xs"><i class="icon  glyphicon glyphicon-plus"></i> 添加</a>
                    </div>
                </div>
                <!-- /.box-header -->

                <div class="box-body table-responsive no-padding">

                    <table class="table table-hover">
                        <tr>
                            <th>ID</th>
                            <th>名称</th>
                            <th>分类</th>
                            <th style="width: 300px;">操作</th>
                        </tr>

                        @foreach ($product as $item)
                        <tr>
                            <td>{{$item->id}}</td>
                            <td>{{$item->name}}</td>
                            <td>
                                <?php
                                    $categorys = $category::where('cat_id',$item->cat_id)->pluck('cat_name');
                                    echo $categorys;
                                ?>
                            </td>
                            <td>
                                <a href="{{Route('admin.product.edit',$item->id)}}?back_url=<?php echo urlencode('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);?>" type="button" class="btn  btn-default btn-xs"><i class="icon  glyphicon glyphicon-edit"></i> 修改</a>
                                <button type="button" class="btn  btn-danger btn-xs"  data-toggle="modal" data-target="#modal{{$item->id}}"><i class="icon  glyphicon glyphicon-remove"></i> 删除</button>

                                <div id="modal{{$item->id}}" class="modal fade">
                                    <div class="modal-dialog">
                                        <div class="modal-content">
                                            <div class="modal-header">
                                                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                                <h4 class="modal-title">删除警告:</h4>
                                            </div>
                                            <div class="modal-body">
                                                <p>确认要删除产品[{{$item->name}}]吗?</p>
                                            </div>
                                            <div class="modal-footer">


                                                {!! Form::open(['route' => ['admin.product.destroy', $item->id],'name'=>$item->id, 'method'=>'delete']) !!}

                                                <input type="hidden" name="pre_url" value="<?php if(@$_SERVER['HTTP_REFERER']==''){ ?>{{route('admin.product.index')}}<?php }else{echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];}?>"/>

                                                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>

                                                {!! Form::submit('删除',array('class' => 'btn btn-danger')) !!}

                                                {!!Form::close()   !!}
                                            </div>
                                        </div><!-- /.modal-content -->
                                    </div><!-- /.modal-dialog -->
                                </div><!-- /.modal -->

                            </td>
                        </tr>
                        @endforeach

                    </table>

                </div>
                <!-- /.box-body -->

                <div class="box-footer">
                    <!-- 分页 -->
                    <div class="pull-right no-margin-pager">
                        {!! $product->render() !!}
                    </div>

                </div>
            </div>
        </div>
    </div>

</section>
<!-- /.content -->

@endsection